﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLBH.Models;
using QLBH.Controllers;

namespace QLBH.Modules
{
    public partial class ucCategory : UserControl
    {
        private CategoryController controller;
        public ucCategory()
        {
            InitializeComponent();
            controller = new CategoryController(this);
        }

        public void DisplayData(List<Models.CategoryModel> data)
        {
            this.dgvCategory.DataSource = data;
        }

        public CategoryModel getCurrentSelectedItem()
        {
            if (dgvCategory.SelectedRows.Count > 0)
            {
                return dgvCategory.SelectedRows[0].DataBoundItem as CategoryModel;
            }
            return null;       
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            controller.Add();
        }

        private void ucCategory_Load(object sender, EventArgs e)
        {
            controller.LoadData();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            controller.Edit();
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            controller.Delete();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            controller.LoadData();
        }
    }
}
